﻿namespace OverStore.Runtime.ObjectRepository.CallbackManager
{
    /// <summary>
    /// Provide notification to instance about persistence operations performed on it.
    /// </summary>
    /// <typeparam name="TInstance">The type of the instance.</typeparam>
    public interface ICallbackManager<TInstance> : IRuntimeComponent
        where TInstance : class
    {
        /// <summary>
        /// Performs operations as response to specified action. 
        /// If method returns <c>false</c>, the operation which provides callback must be interrupted.
        /// Some operation can't be interrupted.
        /// </summary>
        /// <param name="instance">The instance been argument of persistence operation.</param>
        /// <param name="operation">The persistence operation performed on instance.</param>
        /// <returns><c>true</c> to continue persistence operation, <c>false</c> to stop persistence operation.</returns>
        /// <exception cref="PersistingRuntimeException">Error occured due callback processing.</exception>
        bool Callback(TInstance instance, PersistenceOperation operation);
    }
}